package com.me.control;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.constant.Constant;
import com.me.enums.ScreenEnum;
import com.me.happybugs.HappyBugs_Main;
import com.me.helper.PreferencesData;


public class CreateWindown {
	float w;
	float h;
	static Group group;
	ScrollPane scroll;
	Label lb_about;
	
	public static Group confirmExit(){
		group = new Group();
		Image img_bgNen = new Image(Constant.atlas.findRegion("datagame/bg_popup"));
		Image img_bg = new Image(Constant.atlas.findRegion("datagame/bg_result"));
		img_bg.setWidth(600);
		img_bg.setX((Constant.STAGE_WIDTH - img_bg.getWidth())/2);
		img_bg.setY((Constant.STAGE_HEIGHT - img_bg.getHeight())/2 - 10);
		
		Label lb_ask = new Label("Exit game ?", Constant.skin, "label45_bold");
		lb_ask.setX((Constant.STAGE_WIDTH - lb_ask.getWidth())/2);
		lb_ask.setY(460);
		
		TextButton btn_Yes, btn_No;
		btn_No = new TextButton("No", Constant.skin, "textButton_45_bold");
		btn_No.setX(400);
		btn_No.setY(210);
		btn_No.setHeight(100);
		btn_No.setWidth(210);
		btn_No.addListener(new ClickListener(){

			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				HappyBugs_Main.getScreenManager().createScreen(ScreenEnum.MENU_SCREEN);
				HappyBugs_Main.getScreenManager().getScreen().show();
				Constant.b_backDevice = true;
			}
			
		});
		
		btn_Yes = new TextButton("Yes", Constant.skin, "textButton_45_bold");
		btn_Yes.setX(640);
		btn_Yes.setY(210);
		btn_Yes.setHeight(100);
		btn_Yes.setWidth(210);
		btn_Yes.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				System.gc();
				System.exit(1);
				Gdx.app.exit();
			}
			
		});
		
		group.addActor(img_bgNen);
		group.addActor(img_bg);
		group.addActor(lb_ask);
		group.addActor(btn_No);
		group.addActor(btn_Yes);
		
		return group;
	}
	
	public static Group Soundoption(){
		group = new Group();
		Image img_bgNen = new Image(Constant.atlas.findRegion("datagame/bg_popup"));
		Image img_bg = new Image(Constant.atlas.findRegion("datagame/bg_result"));
		img_bg.setWidth(600);
		img_bg.setX((Constant.STAGE_WIDTH - img_bg.getWidth())/2);
		img_bg.setY((Constant.STAGE_HEIGHT - img_bg.getHeight())/2 - 10);
		
		Label lb_Option = new Label("Options", Constant.skin, "label45_bold");
		lb_Option.setX((Constant.STAGE_WIDTH - lb_Option.getWidth())/2-20);
		lb_Option.setY(500);
		
		final CheckBox cb_Sound;
		final CheckBox cb_Music;
		Label lb_Sound, lb_Music;
		
		lb_Sound = new Label("Sound: ", Constant.skin, "label40_sound");
		lb_Sound.setX(480);
		lb_Sound.setY(390);
		
		cb_Sound = new CheckBox("", Constant.skin, "radio");
		cb_Sound.setX(650);
		cb_Sound.setY(390);
		
		lb_Music = new Label("Music: ", Constant.skin, "label40_sound");
		lb_Music.setX(480);
		lb_Music.setY(310);
		
		cb_Music = new CheckBox("", Constant.skin, "radio");
		cb_Music.setX(650);
		cb_Music.setY(310);
		
		TextButton btn_back = new TextButton("Back", Constant.skin, "textButton_subMenu");
		btn_back.setX(500);
		btn_back.setY(175);
		btn_back.setWidth(230);
		
		if(PreferencesData.getBoolRememberMusic()){
			cb_Music.setChecked(true);
		}else{
			cb_Music.setChecked(false);
		}
		
		if(PreferencesData.getBoolRememberSound()){
			cb_Sound.setChecked(true);
		}else{
			cb_Sound.setChecked(false);
		}
		
		btn_back.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				if(cb_Music.isChecked()){
					PreferencesData.setBoolRememberMusic(true);
				}else{
					PreferencesData.setBoolRememberMusic(false);
				}
				
				if(cb_Sound.isChecked()){
					PreferencesData.setBoolRememberSound(true);
				}else{
					PreferencesData.setBoolRememberSound(false);
				}
				
				HappyBugs_Main.getScreenManager().createScreen(ScreenEnum.MENU_SCREEN);
				HappyBugs_Main.getScreenManager().getScreen().show();
				Constant.b_backDevice = true;
			}
			
		});
		
		group.addActor(img_bgNen);
		group.addActor(img_bg);
		group.addActor(lb_Option);
		group.addActor(lb_Music);
		group.addActor(lb_Sound);
		group.addActor(cb_Music);
		group.addActor(cb_Sound);
		group.addActor(btn_back);
		
		return group;
	}
}
